import React from 'react';
import { View, Text, TouchableOpacity, StyleSheet, Modal,PermissionsAndroid } from 'react-native';
import { requestCameraPermission,requestWritePermission } from '../../utils/Permission';


const PermissionDialog = ({ visible, onClose,title,content,permissions }) => {
  const requestPermission = async () => {
    try {
      
      const granteds = await PermissionsAndroid.requestMultiple(permissions)

      onClose();
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <Modal
      visible={visible}
      transparent={true}
      animationType="fade"
    >
      <View style={styles.container}>
        <View style={styles.dialog}>
          <View style={{ flexDirection: 'row', justifyContent: 'center',alignItems: 'center' }}>
            <Text style={styles.title}>{title}</Text>
          </View>
          
          <Text style={styles.description}>
            {content}
          </Text>
          
          <TouchableOpacity 
            style={styles.applyButton}
            onPress={requestPermission}
          >
            <Text style={styles.applyButtonText}>申请权限</Text>
          </TouchableOpacity>

          <TouchableOpacity 
            style={styles.rejectButton}
            onPress={onClose}
          >
            <Text style={styles.rejectButtonText}>拒绝</Text>
          </TouchableOpacity>
        </View>
      </View>
    </Modal>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'rgba(0,0,0,0.5)',
    justifyContent: 'center',
    alignItems: 'center',
  },
  dialog: {
    width: '80%',
    backgroundColor: 'white',
    borderRadius: 8,
    padding: 20,
  },
  title: {
    fontSize: 18,
    fontWeight: 'bold',
    color: '#000000',
  },
  description: {
    marginTop: 10,
    fontSize: 14,
    color: '#666666',
  },
  applyButton: {
    marginTop: 20,
    backgroundColor: '#FFE814',
    borderRadius: 4,
    padding: 12,
    alignItems: 'center',
  },
  applyButtonText: {
    color: '#000000',
    fontSize: 16,
  },
  rejectButton: {
    marginTop: 10,
    padding: 12,
    alignItems: 'center',
  },
  rejectButtonText: {
    color: '#666666',
    fontSize: 16,
  },
});

export default PermissionDialog;